package Servlet;

import bean.User;
import dao.UserDao;
import utils.JDBCUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.*;

@WebServlet(name = "chat_Reset", value = "/chat_Reset")
public class chatReset extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html;charset=UTF-8");
        String userName = request.getParameter("userName");
        String newPassword = request.getParameter("newPassword");
        String newpassword = request.getParameter("newpassword");
        if(newpassword.equals(newPassword)){
            UserDao userDao = new UserDao();
            User user = new User();
            user.setId(userName); //id
            user.setPassWord(newPassword);
            try {
                boolean  flag = userDao.reset(user,"passWord");
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            request.setAttribute("isReset","istrue");

            request.getRequestDispatcher("/index.jsp").forward(request,response);
        }else {
            request.setAttribute("isReset","isfalse");

            request.getRequestDispatcher("/Update_password.jsp").forward(request,response);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
